package com.xh.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author wen
 * @apiNote OrderDetailController
 * @since 2021-12-10
 */
@Slf4j
@RestController
@RequestMapping("/core")
public class OrderCoreController {

    @GetMapping("v1/detail/{id}")
    public String detail(@PathVariable("id") Long id) throws InterruptedException {
        int random = ThreadLocalRandom.current().nextInt();
        if (random % 2 == 0) {
            throw new IllegalArgumentException("业务异常");
        }
        return String.format("{\"orderId\":\"%s\",\"clientSecret\":\"1D2728858C7F36F4A8D04DDC4877B3E8\",\"path\":\"https://erp-open.hupun.com/api\",\"timeout\":30000}", id);
    }

    @GetMapping("v2/detail/{id}")
    public String detailV2(@PathVariable("id") Long id) throws InterruptedException {
        int random = ThreadLocalRandom.current().nextInt();
        if (random % 2 == 0) {
            Thread.sleep(5_000);
        }
        return "order-detail-v2";
    }

}
